package com.example.adapterviewfilpperdemo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterViewFlipper;
import android.widget.Button;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    AdapterViewFlipper flipper;
    Button preBtn;
    Button nextBtn;
    Button autoBtn;

    int[] imgIds = {
            R.drawable.img1,R.drawable.img2,R.drawable.img3,R.drawable.img4
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        flipper = findViewById(R.id.flipper);
        preBtn = findViewById(R.id.prev_btn);
        nextBtn = findViewById(R.id.next_btn);
        autoBtn = findViewById(R.id.auto_btn);

        MyFilpperAdapter adapter = new MyFilpperAdapter(this,imgIds);
        flipper.setAdapter(adapter);

        preBtn.setOnClickListener(this);
        nextBtn.setOnClickListener(this);
        autoBtn.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.prev_btn:
                flipper.showPrevious();
                flipper.stopFlipping();
                break;
            case R.id.next_btn:
                flipper.showNext();
                flipper.stopFlipping();
                break;
            case R.id.auto_btn:
                flipper.startFlipping();
                break;
                default: break;
        }
    }
}
